<template>
  <div class="LogManage">
    <el-row class="LogManage_row_one">
      <el-date-picker
        class="row_one_picker"
        v-model="date"
        type="date"
        placeholder="选择日期">
      </el-date-picker>
      <el-select class="row_one_select" v-model="typeValue" placeholder="请选择返回状态">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <el-input prefix-icon="el-icon-search" class="row_one_input"  v-model="keyWord" placeholder="请输入操作者名称"></el-input>
    </el-row>
    <el-row class="LogManage_row_two">
      <el-table
        :data="logArray"
        width="100%"
        height="90%"
        :border="true"
        highlight-current-row
      >
        <el-table-column
          prop="logUser"
          label="操作者"
          width="75px"
        >
        </el-table-column>
        <el-table-column
          prop="logClientIP"
          label="客户端ip"
        >
        </el-table-column>
        <el-table-column
          prop="logUrl"
          label="请求地址"
        >
        </el-table-column>
        <el-table-column
          prop="logArgs"
          label="请求参数"
        >
        </el-table-column>
        <el-table-column
          prop="logResult"
          label="返回参数"
        >
        </el-table-column>
        <el-table-column
          prop="logType"
          label="请求状态"
          width="50px"
        >
        </el-table-column>
        <el-table-column
          prop="logTime"
          label="请求时间"
        >
        </el-table-column>
      </el-table>
    </el-row>
  </div>
</template>

<script>
export default {
  name: "LogManage",
  data() {
    return {
      logArray: [],
      date: '',
      typeValue: '',
      options: [
        {
          value: 'info',
          label: 'info'
        }, {
          value: 'err',
          label: 'err'
        }
      ],
      keyWord: '',
    }
  },
  mounted() {
    this.selLogInfo();
  },
  methods:{
    selLogInfo(){
      let params = new URLSearchParams();
      this.logArray = [];
      //时间格式化
      if(this.date != ''){
        var time = new Date(this.date);
        var year = time.getFullYear();
        var month = time.getMonth()+1<10?'0'+(time.getMonth()+1):time.getMonth()+1;
        var day = time.getDate()<10?'0'+time.getDate():time.getDate();
        let logTime = year + "/" + month + "/" + day;
        params.append("logTime" , logTime);
      }else{
        params.append("logTime" , this.date);
      }
      //参数填入
      params.append("logType" , this.typeValue);
      params.append("logUser" , this.keyWord)
      this.$api.selLogInfo(params)
      .then(res =>{
        if(res.code === '200'){
          this.logArray = res.data;
        }else{
          this.$message.error(res.msg);
        }
      })
      .catch(err =>{})
    }
  },
  watch:{
    date(){
      this.selLogInfo();
    },
    typeValue(){
      this.selLogInfo();
    },
    keyWord(){
      this.selLogInfo();
    }
  }

}
</script>

<style scoped>
.LogManage {
  width: 100%;
  height: 100%;
}

.LogManage_row_one {
  height: 10%;
  width: 90%;
  margin-left: 3%;
  top: 2%;
}

.LogManage_row_two {
  height: 86%;
  width: 90%;
  margin-left: 3%;
  margin-top: 2%;
}

.row_one_input{
  margin-left: 1%;
  width: 15%;
}
.row_one_picker{
  width: 15%;
}
.row_one_select{
  margin-left: 1%;
  width: 15%;
}
</style>
